import 'dart:async';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';

class AppRefresh extends StatefulWidget {
  Widget child;

  /// Refresh callback.
  /// Triggered on refresh.
  /// When null, disable refresh.
  /// The Header current state is [IndicatorMode.processing].
  /// More see [IndicatorNotifier._onTask].
  final FutureOr Function()? onRefresh;

  /// Load callback.
  /// Triggered on load.
  /// When null, disable load.
  /// The Footer current state is [IndicatorMode.processing].
  /// More see [IndicatorNotifier._onTask].
  final FutureOr Function()? onLoad;

  /// EasyRefresh controller.
  final EasyRefreshController? controller;

  /// Header indicator.
  final Header? header;

  /// Footer indicator.
  final Footer? footer;

  AppRefresh(
      {required this.child,
        this.controller,
        this.onLoad,
        this.onRefresh,
        this.header,
        this.footer,
        Key? key})
      : super(key: key);
  @override
  State<AppRefresh> createState() => _AppRefreshState();
}

class _AppRefreshState extends State<AppRefresh> {
  @override
  Widget build(BuildContext context) {
    return EasyRefresh(
      controller: widget.controller,
      header: widget.header ??
          const MaterialHeader(),
          // const CustomMaterialHeader(
          //   clamping: false,
          //   springRebound: true,
          // ),
      footer: widget.footer ?? MaterialFooter()
          // const CustomMaterialFooter(
          //   clamping: false,
          //   springRebound: true,
          //   position: IndicatorPosition.locator,
          // )
      ,
      onRefresh: widget.onRefresh,
      onLoad: widget.onLoad,
      child: widget.child,
    );
  }
}
